<template>
  <div>
    <el-row style="display: flex; align-items: center;">
      <el-col :span="20">
        <span style="font-size: 20px; margin-left: 15px;color: rgb(120, 109, 109);">年份：2024</span>
        <div :style="{ minHeight: height, minWidth: width }">
          <div ref="chart" class="chart" :style="{ height: height, width: width }" />
        </div>
      </el-col>
      <el-col :span="4">
        <div class="vertical-radio">
          <el-radio-group v-model="pointValue" @change="changeChartValue">
            <el-radio v-for="item in options" :key="item.value" :value="item.value" :label="item.value"></el-radio>
          </el-radio-group>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import * as echarts from 'echarts';
require('echarts/theme/macarons') // echarts theme
import resize from "@/views/dashboard/mixins/resize"
export default {
  mixins: [resize],
  name: "OrderLineChart",
  props: {
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '360px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },

  },
  data() {
    return {
      // 总条数
      pointValue: "全量高价塔数量",
      options: [
        {
          value: "全量高价塔数量",
          label: "全量高价塔数量",
        },
        {
          value: "新建高价塔数量",
          label: "新建高价塔数量",
        },
        {
          value: "全量高价塔占比",
          label: "全量高价塔占比",
        },
        {
          value: "新建高价塔占比",
          label: "新建高价塔占比",
        },
      ],

      highTowerCount: [],
      highTowerNewCount: [],
      highTowerRatio: [],
      highTowerNewRatio: [],
      staDate: [],
      flowTrendList: []
      ,
    }
  },
  mounted() {

    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  created() {
  },
  methods: {
    initData(val) {
      this.flowTrendList = val;
      this.checkSearchValue(this.pointValue);
    },
    initChart() {
      this.chart = echarts.init(this.$refs.chart, 'macarons')
      this.setOptions()
    },
    setOptions() {
      this.chart.setOption({
        grid: [{
          left: '60',
          right: '30'
        }],
        title: [{
          text: this.pointValue,
          textStyle: {
            fontSize: 16,
            fontWeight: 'bolder',
            color: '#000000'          // 主标题文字颜色
          },
          x: 'center',
          y: 'top',
          textAlign: 'left'
        }],
        xAxis: {
          data: this.staDate,
          type: 'category',
          boundaryGap: true,
          axisLabel: {
            rotate: 0
          },
          textStyle: {
            fontSize: 12,
          },
          axisTick: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: "#000000"
            }
          },
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            lineStyle: {
              color: "#C0CADB",
              width: 3,
            },
          },
          padding: [5, 10]
        },
        yAxis: [

          {
            type: 'value',
            name: '',
            minInterval: 0.1,
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#000000"
              }
            }
          }
        ],
        series: [
          {
            name: '全量高价塔数量',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                // color: '#2c7be5',
              }
            },
            label: {
              show: true,
              position: 'top'
            },
            data: this.highTowerCount,

          },
          {
            name: '新建高价塔数量',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                // color: '#6ba3ed',
              }
            },
            label: {
              show: true,
              position: 'top'
            },
            data: this.highTowerNewCount,

          },
          {
            name: '全量高价塔占比',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                // color: '#8bb6f1',
              }
            },
            label: {
              show: true,
              position: 'top'
            },
            data: this.highTowerRatio,

          },
          {
            name: '新建高价塔占比',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                // color: '#abcaf5',
              }
            },
            label: {
              show: true,
              position: 'top'
            },
            data: this.highTowerNewRatio,

          }
        ]
      })
    },
    changeChartValue(value) {
      this.pointValue = value;
      this.checkSearchValue(this.pointValue);
    },

    checkSearchValue(val) {
      this.staDate = [];
      this.highTowerCount = [];
      this.highTowerNewCount = [];
      this.highTowerRatio = [];
      this.highTowerNewRatio = [];
      const { staDate, highTowerCount, highTowerNewCount, highTowerRatio, highTowerNewRatio } = this;
      this.flowTrendList.map((item) => {
        if (item.staDate) {
          item.staDate = item.staDate.replace(/2023-/g, "");
          if (item.staDate.length <= 2) {
            item.staDate = item.staDate
          }
          return staDate.push(item.staDate);
        } else {
          staDate.push(0);
        }
      });
      if (val.includes("全量高价塔数量")) {
        this.flowTrendList.map((item) => {
          if (item.highTowerCount) {
            return highTowerCount.push(item.highTowerCount);
          } else {
            highTowerCount.push(0);
          }
        });
      } else {
        this.highTowerCount = [];
      }
      if (val.includes("全量高价塔占比")) {
        this.flowTrendList.map((item) => {
          if (item.highTowerRatio) {
            return highTowerRatio.push(item.highTowerRatio);
          } else {
            highTowerRatio.push(0);
          }
        });
      } else {
        this.highTowerRatio = [];
      }
      if (val.includes("新建高价塔数量")) {
        this.flowTrendList.map((item) => {
          if (item.highTowerNewCount) {
            return highTowerNewCount.push(item.highTowerNewCount);
          } else {
            highTowerNewCount.push(0);
          }
        });
      } else {
        this.highTowerNewCount = [];
      }

      if (val.includes("新建高价塔占比")) {
        this.flowTrendList.map((item) => {
          if (item.highTowerNewRatio) {
            return highTowerNewRatio.push(item.highTowerNewRatio);
          } else {
            highTowerNewRatio.push(0);
          }
        });
      } else {
        this.highTowerNewRatio = [];
      }
      this.initChart();
    },
    handleColumnCheckedChange(data) {
      for (let item in this.columns) {
        const label = this.columns[item].label;
        this.columns[item].visible = data.includes(label);
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val.page;
      console.log(val)
    },
  },


}
</script>
<style scoped lang="scss">
.vertical-radio .el-radio {
  display: block;
  margin-bottom: 10px;
}
::v-deep .el-radio {
  .el-radio__input {
    .el-radio__inner {
      border-radius: 2px;
    }
  }
  .el-radio__input.is-checked .el-radio__inner::after {
    content: '';
    width: 8px;
    height: 3px;
    border: 2px solid white;
    border-top: transparent;
    border-right: transparent;
    text-align: center;
    display: block;
    position: absolute;
    top: 2px;
    left: 2px;
    vertical-align: middle;
    transform: rotate(-45deg);
    border-radius: 0px;
    background: none;
  }
}


</style>
